package com.itheima.service.db.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.itheima.domain.db.User;
import com.itheima.mapper.UserMapper;
import com.itheima.service.db.UserService;
import org.apache.dubbo.config.annotation.Service;
import org.springframework.beans.factory.annotation.Autowired;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public Long save(User user) {
        userMapper.insert(user);
        return user.getId();
    }

    @Override
    public User findByPhone(String phone) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("phone", phone);
        return userMapper.selectOne(wrapper);
    }

    /**
     *根据用户id查询手机号
     * @param userId
     * @return
     */
    @Override
    public String findPhoneByUserId(Long userId) {
        //1.获取用户
        User user = userMapper.selectById(userId);
        return user.getPhone();
    }

    /**
     * 修改手机号 - 3 保存
     * @param user
     */
    @Override
    public void update(User user) {
        userMapper.updateById(user);
    }
    @Override
    public String userIdByPhone(Long userID) {
        User user = userMapper.selectById (userID);
        return user.getPhone ();
    }
}
